package zust.se.delicious.action;

import java.util.Map;

import zust.se.delicious.service.UserService;
import zust.se.delicious.vo.SessionUserBean;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class FollowActionAjax extends ActionSupport {
	private UserService userService;

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	private int uid;
	private int fid;
	private boolean success;

	public boolean getSuccess() {
		return success;
	}

	public String follow() {
		Map session = ActionContext.getContext().getSession();
		SessionUserBean sessionUser = (SessionUserBean) session.get("sessionUser");
		if (sessionUser != null) {
			uid = sessionUser.getId();
			success = userService.follow(uid, fid);
		}
		return SUCCESS;
	}

	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	public int getFid() {
		return fid;
	}

	public void setFid(int fid) {
		this.fid = fid;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String unfollow() {
		Map session = ActionContext.getContext().getSession();
		SessionUserBean sessionUser = (SessionUserBean) session.get("sessionUser");
		if (sessionUser != null) {
			uid = sessionUser.getId();
			success = userService.unfollow(uid, fid);
		}
		return SUCCESS;
	}
}
